package ch11;

import java.util.*;

class _20_HashMapEx4 {
	public static void main(String[] args) {
		String[] data = { "A", "K", "A", "K", "D", "K", "A", "K", "K", "K",	"Z", "D" };

		Map<String,Integer> map = new HashMap<String,Integer>();
		for (int i = 0; i < data.length; i++) {
			if (map.containsKey(data[i])) {				
				map.put(data[i], map.get(data[i])+1);
			} else {
				map.put(data[i],1);
			}
		}
		
		Set<Map.Entry<String,Integer>> entrySet = map.entrySet();
		for(Map.Entry<String,Integer> entry:entrySet)
			System.out.println(entry.getKey() + " : " + printBar('#', entry.getValue()) + " " + entry.getValue());
	} 

	public static String printBar(char ch, int value) {
		char[] bar = new char[value];
		for (int i = 0; i < bar.length; i++) bar[i] = ch;
		return new String(bar);
	}
}
/*
D : ## 2
A : ### 3
Z : # 1
K : ###### 6
*/